package cn.terminus.biz.customer.settledenterpriseinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.analysis.CustomerNatureIndustryNumResultDto;
import cn.terminus.common.customer.bean.analysis.SettledEnterpriseAnalysisDto;
import cn.terminus.common.customer.bean.analysis.SettledEnterpriseLabelNumResultDto;
import cn.terminus.common.customer.bean.settledenterpriseinfo.dto.*;
import cn.terminus.data.customer.settledenterpriseinfo.dao.SettledEnterpriseInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (SettledEnterpriseInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:19:08
 */
@Component
public class SettledEnterpriseInfoManager extends AbstractTerminusManager {
    @Autowired
    private SettledEnterpriseInfoDao settledEnterpriseInfoDao;

    public Integer add(SettledEnterpriseInfoNewDto dto) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(SettledEnterpriseInfoEditDto dto) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public SettledEnterpriseInfoResultDto gets(SettledEnterpriseInfoGetsDto dto) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }


    public Integer delete(SettledEnterpriseInfoDeleteDto dto) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<SettledEnterpriseInfoResultDto> page(SettledEnterpriseInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<SettledEnterpriseInfoResultDto> result = (Page<SettledEnterpriseInfoResultDto>) settledEnterpriseInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), SettledEnterpriseInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }


    public Integer updateSettledStatus(Long id) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.updateSettledStatus(id);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer updateSettledStatusToCustomer(List<Long> ids) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.updateSettledStatusToCustomer(ids);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer updateStage(Long cboCustomerId) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.updateStage(cboCustomerId);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomerNatureIndustryNumResultDto> analysisSettledEnterpriseIndustry(SettledEnterpriseAnalysisDto dto) throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.analysisSettledEnterpriseIndustry(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomerNatureIndustryNumResultDto> analysisSettledEnterpriseNature(SettledEnterpriseAnalysisDto dto)throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.analysisSettledEnterpriseNature(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<SettledEnterpriseLabelNumResultDto> analysisSettledEnterpriseLabel(SettledEnterpriseAnalysisDto dto)throws DataAccessException {
        try {
            return settledEnterpriseInfoDao.analysisSettledEnterpriseLabel(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
